package com.example.mykotlin.base.config.converter

import com.example.mykotlin.base.util.Constant
import java.time.LocalDate
import java.time.format.DateTimeParseException
import org.apache.commons.lang3.StringUtils
import org.springframework.core.convert.converter.Converter

class StringToLocalDateConverter : Converter<String, LocalDate> {
    override fun convert(source: String): LocalDate? {
        return if (StringUtils.isBlank(source)) null else try {
            LocalDate.parse(source, Constant.DF)
        } catch (pe: DateTimeParseException) {
            null
            // try {
            //     LocalDate.parse(source, DateTimeFormatter.ofPattern("yyyy/MM/dd"))
            // } catch (pe: DateTimeParseException) {
            //     null
            // }
        }
    }


}